package orange.data;

import org.cncitrus.data.common.Params;
import org.cncitrus.data.manager.ParamsManager;
import org.json.JSONArray;
import org.json.JSONObject;

public class Chineseexport {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			String[] content = Filemanager.FileReader("chineseexport").split("\n");
			JSONArray jarray = new JSONArray();
			for(String s:content){
				if(s.contains("2010")){
					JSONObject bean = new JSONObject();
					String[] array = s.split(",");
					int length = array.length;
					bean.put("year", array[0]);
					bean.put("code", array[1]);
					if(length>2){
						bean.put("country", array[2]);
					}else{
						bean.put("country", "");
					}
					if(length>3){
						bean.put("money", array[3]);
					}else{
						bean.put("money", "");
					}
					if(length>4){
						bean.put("total", array[4]);
					}else{
						bean.put("total", "");
					}					
					jarray.put(bean);
					}
				}
			String TABLE_NAME = "orange_z_chuliang";
			StringBuffer sb = new StringBuffer();
			sb.append("INSERT INTO "+TABLE_NAME+" ("+Params.ChinaExport.year+","+Params.ChinaExport.code+","+Params.ChinaExport.country+","+Params.ChinaExport.money+","+Params.ChinaExport.total+") VALUES ");		
			int length = jarray.length();
			String[] year = new String[length],code  = new String[length],country= new String[length],money = new String[length],total = new String[length];
			for(int i=0;i<length;i++){
				JSONObject bean = jarray.getJSONObject(i);
				year[i] = bean.getString("year");
				code[i] = bean.getString("code");
				country[i] = bean.getString("country");
				money[i] = bean.getString("money");
				total[i] = bean.getString("total");
			}
			sb.append(ParamsManager.getInsertString(year,code,country,money,total));
			System.out.println(sb.toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	}

}
